package com.zhb.lkd.controller;


import com.zhb.lkd.base.PageResponse;
import com.zhb.lkd.base.ResponseResult;
import com.zhb.lkd.exception.BusinessException;
import com.zhb.lkd.pojos.dto.SkuClassPageDto;
import com.zhb.lkd.pojos.entity.Sku;
import com.zhb.lkd.pojos.entity.SkuClass;
import com.zhb.lkd.service.ISkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author haibin
 * @since 2024-08-18
 */
@RestController
@RequestMapping("/api/vm-service/sku")
@Slf4j
@Api(tags = "商品管理")
public class SkuController {
    @Resource
    private ISkuService skuService;

    @GetMapping("/search")
    @ApiOperation("商品搜索")
    public ResponseResult login(
            @RequestParam(defaultValue = "1") Integer pageIndex,
            @RequestParam(defaultValue = "10") Integer pageSize,
            String skuName) {
        log.info("商品搜索{}", pageIndex);
        PageResponse pageResponse = skuService.search(pageIndex,pageSize,skuName);
        return ResponseResult.ok(pageResponse);
    }


    @PostMapping("")
    @ApiOperation("新增商品")
    public ResponseResult create(@RequestBody Sku sku) {
        log.info("新增商品{}", sku);
        skuService.create(sku);
        return ResponseResult.ok();
    }


    @PutMapping()
    @ApiOperation("修改商品")
    public ResponseResult updateById(@RequestBody Sku sku) {
        log.info("修改商品{}", sku);
        if (sku.getSkuId()==0||sku.getSkuId()==null){
            throw new BusinessException(500,"商品id不能为空");
        }
        boolean b = skuService.updateById(sku);
        return ResponseResult.ok();
    }
}
